<?php

class Edit extends TPage
{
	public $payment_manager;
	public $payment;
	
	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->payment_manager = $this->Application->Modules['payments'];
		
		$this->payment = $this->payment_manager->getPaymentById($this->Request['id']);
		if(!($this->payment instanceof PaymentRecord))
			$this->Response->redirect($this->Service->constructUrl('organizer.payments.Add'));
			
		if(!$this->IsPostback)
			$this->readData();
	}
	
	public function readData()
	{
		$this->value->Text = $this->payment->getValue();
		$this->description->Text = $this->payment->getDescription();
	}
	
	public function saveButtonClicked($sender, $params)
	{
		if($this->Page->IsValid)
		{
			$this->payment->setValue($this->value->Text);
			$this->payment->setDescription(String::format($this->description->Text));
			
			$result = $this->payment_manager->updatePaymentByPaymentRecord(
													$this->payment
												);

			if($result)
				$this->info->Text = '<p>'.Prado::localize('Changes saved').'</p>';
			else
				$this->info->Text = '<p>'.Prado::localize('Changes not saved').'</p>';
		}
	}
	
	public function getCurrencyName()
	{
		$setting_manager = $this->Application->Modules['settings'];
		if($setting = $setting_manager->getSettingByName(SettingManager::$CURRENCY_NAME))
			return $setting->getValue() != '' ? $setting->getValue() : '-';
		return '-';
	}
}

?>